package com.leo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 * @ClassName WritableImageDemo
 * @Description
 * @Author wangss
 * @date 2020.06.02 21:47
 * @Version 1.0
 */
public class WritableImage1Demo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane an = new AnchorPane();
        an.setStyle("-fx-background-color: #e7eeea");
        Scene scene = new Scene(an);

        Image image = new Image("images/18.jpeg");

        WritableImage writableImage = new WritableImage(image.getPixelReader(), 400, 400);

        PixelWriter pixelWriter = writableImage.getPixelWriter();

        for (int x = 0; x < 100; x++) {
            for (int y = 0; y < 100; y++) {
                pixelWriter.setColor(x, y, Color.valueOf("#C4EEE9"));
            }
        }

        ImageView imageView = new ImageView(writableImage);

        an.getChildren().add(imageView);
        primaryStage.setScene(scene);
        primaryStage.setTitle("ImageViewDemo");
        primaryStage.setWidth(600d);
        primaryStage.setHeight(600d);
//        primaryStage.setResizable(false);
        primaryStage.show();
    }
}
